package com.ruoyi.ruoyiyinzheng.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.ruoyiyinzheng.domain.vo.StRecieptRatioVo;
import com.ruoyi.ruoyiyinzheng.domain.bo.StRecieptRatioBo;
import com.ruoyi.ruoyiyinzheng.service.IStRecieptRatioService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 配方比例控制器
 * 前端访问路由地址为:/ruoyiyinzheng/recieptRatio
 *
 * @author ruoyi
 * @date 2023-09-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/recieptRatio")
public class StRecieptRatioController extends BaseController {

    private final IStRecieptRatioService iStRecieptRatioService;

    /**
     * 查询配方比例列表
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:list")
    @GetMapping("/list")
    public TableDataInfo<StRecieptRatioVo> list(StRecieptRatioBo bo, PageQuery pageQuery) {
        return iStRecieptRatioService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出配方比例列表
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:export")
    @Log(title = "配方比例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StRecieptRatioBo bo, HttpServletResponse response) {
        List<StRecieptRatioVo> list = iStRecieptRatioService.queryList(bo);
        ExcelUtil.exportExcel(list, "配方比例", StRecieptRatioVo.class, response);
    }

    /**
     * 获取配方比例详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:query")
    @GetMapping("/{id}")
    public R<StRecieptRatioVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iStRecieptRatioService.queryById(id));
    }

    /**
     * 新增配方比例
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:add")
    @Log(title = "配方比例", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StRecieptRatioBo bo) {
        return toAjax(iStRecieptRatioService.insertByBo(bo));
    }

    /**
     * 修改配方比例
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:edit")
    @Log(title = "配方比例", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StRecieptRatioBo bo) {
        return toAjax(iStRecieptRatioService.updateByBo(bo));
    }

    /**
     * 删除配方比例
     *
     * @param ids 主键串
     */
    @SaCheckPermission("ruoyiyinzheng:recieptRatio:remove")
    @Log(title = "配方比例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iStRecieptRatioService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
